const { getCustomers, addCustomers, hasCustomers, delCustomers, getCustomerById, changeCustomers, getCustomerBySalesMen, CustomersLogin } = require('../dao/customersDao');

module.exports.getCustomers = async function(pageSize, cutPage, type, value) {
    let customers = await getCustomers(pageSize, cutPage, type, value)
    return customers;
};
module.exports.addCustomers = async function(account, password, name, age, gender, phone, salesMenId) {
    let result = await hasCustomers(account, password, name, age, gender, phone, salesMenId)
    if (result.length > 0) {
        return {
            message: '添加失败,该客户已存在',
            code: '0'
        };
    } else {
        addCustomers(account, password, name, age, gender, phone, salesMenId)
        return {
            message: '添加成功',
            code: '1'
        };
    }
};
module.exports.delCustomers = async function(_id) {
    let result = await delCustomers(_id)
    if (result > 0) {
        return {
            message: '删除成功',
            code: '1'
        }
    } else {
        return {
            message: '删除失败',
            code: '0'
        }
    }
};
module.exports.getCustomerById = async function(_id) {
    let customers = await getCustomerById(_id)
    return customers;
};
module.exports.changeCustomers = async function(_id, account, password, name, age, gender, phone, salesMenId) {
    let changeResult = await changeCustomers(_id, account, password, name, age, gender, phone, salesMenId)
    if (changeResult > 0) {
        return {
            message: '修改成功',
            code: '1'
        }
    } else {
        return {
            message: '修改失败',
            code: '0'
        }
    }
};
module.exports.getCustomerBySalesMen = async function(salesMenId, pageSize, cutPage, type, value) {
    let customers = await getCustomerBySalesMen(salesMenId, pageSize, cutPage, type, value)
    return customers;
};
module.exports.CustomersLogin = async function(account, password) {
    let result = await CustomersLogin(account, password)
    if (result.length) {
        return {
            message: '登陆成功',
            code: 1
        }
    } else {
        return {
            message: '登陆失败',
            code: 0
        }
    }
};